package cn.yy.toyflow.controller;

import cn.yy.toyflow.dto.ReqDefRequest;
import cn.yy.toyflow.dto.ResponseBean;
import cn.yy.toyflow.service.FlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class Controller {
    @Autowired
    FlowService service;

    @PostMapping("/newRequest")
    public ResponseBean<?> setupRequest(@RequestBody ReqDefRequest request){
        return service.newRequest(request);
    }

    @GetMapping("/whatToDo/{external_id}")
    public ResponseBean<?> whatToDo(@PathVariable("external_id") String externalID){
        return service.getCurrentState(externalID);
    }

    @PutMapping("/tryFetchAction/{externalID}/{requestID}/{requestActionID}")
    public ResponseBean<?> tryFetchAction(@PathVariable("externalID") String externalID,
                                          @PathVariable("requestID") String requestID,
                                          @PathVariable("requestActionID") String requestActionID){
        return service.checkActionRequest(externalID, requestID, requestActionID);
    }

    @PutMapping("/reportCompleted/{externalID}/{requestID}/{requestActionID}")
    public ResponseBean<?> reportCompleted(@PathVariable("externalID") String externalID,
                                           @PathVariable("requestID") String requestID,
                                           @PathVariable("requestActionID") String requestActionID,
                                           @RequestBody Map<String, String> requestData){
        return service.reportActionCompleted(externalID,requestID,requestActionID,requestData);
    }

    @GetMapping("getRequestData/{requestID}")
    public ResponseBean<?> getRequestData(@PathVariable("requestID") String requestID){
        return service.getRequestData(requestID);
    }
}
